<?php
/* 商户后台首页 */
namespace Shop\Controller;
use Think\Controller;

class SalespromotionController extends ShopController {

    public function lists($p = 1){
        $sal = M("salespromotion");
        $list = $sal->where(array("sid"=>$this->shop_static_info['sid']))->order("id DESC")->page("$p,20")->select();
        $this->assign("list",$list);

        // 数据分页
        $count = $sal->where(array("sid"=>$this->shop_static_info['sid']))->count();
        $page = new \Think\Page($count,20);
        $show = $page->show();
        $this->assign("page",$show);
        $this->assign("pagetitle","促销信息");
        $this->display();
    }

    public function add(){
        if(IS_POST){
            $data=$_POST;

            $data['addtime'] = time();
            $data['image_statue'] = 1;
            $r = M("salespromotion")->add($data);
            if($r){
                successTip("添加成功！",U('lists'));
            }else{
                errorTip(M()->getError());
            }
        }else{
            $this->assign("shopid",$this->shop_static_info['sid']);
            $this->assign("pagetitle","添加促销信息");
            $this->display();
        }
    }

    public function del($id){
        if(M("salespromotion")->delete($id)){
            successTip("删除成功！",U('lists'));
        }else{
            errorTip(M()->getError());
        }
    }

    public function edit($id){
        if(IS_POST){
            $data=$_POST;

            $r = M("salespromotion")->save($data);
            if($r){
                successTip("修改成功！",U('lists'));
            }else{
                errorTip(M()->getError());
            }
        }else{
            $info = M("salespromotion")->find($id);
            $this->assign("data",$info);
            $this->assign("pagetitle","编辑信息");
            $this->display();
        }
    }
}
?>